'use strict';
const loginRule = {
    loginName: {type: 'string', required: true, allowEmpty: false},
    password: {type: 'password', required: true, allowEmpty: false, min: 6},
};
/**
 * 上面的规则可以简写为
 * const loginRule = {
 *  username: 'string',
 *  password: 'password'
 * }
 */
exports.login = function* () {
    if ('GET' == this.request.method){//get请求
        yield this.render("login.html");
    }else{//post
        this.validate(loginRule);
        const params = this.request.body;
        this.logger.info(params);
        //调用service中的login接口登录
        const member = yield this.service.login.login(params);
        //将登陆成功的信息放入session中 后续验证用户登录中通过此信息判断用户是否登录
        this.session.member = member;

        //放回json数据
        this.body = {
            code: 200,
            message: 'success'
        }
    }

};
// 注册
exports.register = function* () {
    if ('GET' == this.request.method){//get请求
        ctx.req.title = '注册-食艺道';
        yield this.render("register.html",ctx.req.title);
    }else{//post
        
    }
}
exports.registerInfo = function* () {
    if ('GET' == this.request.method){//get请求
        ctx.req.title = '注册信息-食艺道';
        yield this.render("registerInfo.html",ctx.req.title);
    }else{//post
        
    }
}
// 用户协议
exports.protocol = function* () {
    ctx.req.title = '用户协议-食艺道';
    yield this.render("protocol.html",ctx.req.title);
}
// 忘记密码
exports.forget = function* () {
    if ('GET' == this.request.method){//get请求
        ctx.req.title = '忘记密码-食艺道';
        yield this.render("forget.html",ctx.req.title);
    }else{//post
        
    }
}

// 修改密码
exports.changePassword = function* () {
    if ('GET' == this.request.method){//get请求
        ctx.req.title = '修改密码-食艺道';
        yield this.render("changePassword.html",ctx.req.title);
    }else{//post
        
    }
}